package com.coldworks.base.task;

import android.content.Context;

import com.coldworks.base.BaseThread;
import com.coldworks.base.manager.BasePrefManager;
import com.coldworks.base.manager.BaseStorageManager;
import com.coldworks.base.util.BaseCONST;

/**
 * 第一次运行清理冗余文件夹
 * 
 * @since 2012-03-23
 */

public class BaseDirsClearTask extends BaseThread {
	private Context ctx;
	private int versionCode;

	public BaseDirsClearTask(Context ctx, int versionCode) {
		this.ctx = ctx;
		this.versionCode = versionCode;
	}

	@Override
	public void run() {
		try {
			Thread.sleep(BaseCONST.TASK.CLEAR_DIRS_SECOND * 1000);
		} catch (InterruptedException e) {
			log.error("", e);
			return;
		}
		if (BasePrefManager.getInstance().getIntFromPrefs(ctx,
				BaseCONST.KEY.FOLDER_CLEARED, 0) == versionCode) {
			log.info("nothing");
			return;
		}
		log.info("start clearing");
		BasePrefManager.getInstance().setIntToPrefs(ctx,
				BaseCONST.KEY.FOLDER_CLEARED, versionCode);

		BaseStorageManager.getInstance().clear(ctx);
	}

}